package com.itheima.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.service.MemberService;
import entity.Result;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/member")
public class MemberController {

    @Reference
    MemberService memberService;

    @RequestMapping("/findByAge")
    public Result findByAge(){

        try {

            Map<String,Object> map = new HashMap();

            List<String> list = new ArrayList();

            list.add("0-18");
            list.add("19-30");
            list.add("31-45");
            list.add("46-60");

            map.put("age",list);

            List<Map<String,Object>> list3 = memberService.findByAge();

            map.put("ageAndValue",list3);

            return new Result(true,"获取成功",map);

        } catch(Exception e) {
            e.printStackTrace();

            return new Result(false,"获取失败");
        }
    }

    @RequestMapping("/findBySex")
    public Result findBySex(){

        try {

            Map<String,Object> map = new HashMap();

            List<String> list = new ArrayList();

            list.add("男");
            list.add("女");

            map.put("sex",list);

            List<Map<String,Object>> list3 = memberService.findBySex();

            map.put("sexValue",list3);

            return new Result(true,"获取成功",map);

        } catch(Exception e) {
            e.printStackTrace();

            return new Result(false,"获取失败");
        }
    }

}
